#! /usr/bin/python
from libs.utils import color, put, on, off
from libs.HueScript import HueScript, TT_SEC

class SunriseScript(HueScript):
    def __init__(self, *posargs, **kwargs):
        HueScript.__init__(self, *posargs, **kwargs)

        self.initial_state = {
            'r': 80,
            'b': 255,
            'data': {
                'bri': 0
            }
        }

    def generateCues(self):
        # make sure everything is off
        sunrise.register(0, color, [[1,2,3]], self.initial_state)
        sunrise.register(0, off, [[1,2,3]] )

        # turn on the lights
        self.initial_state['data'].update({'on': True})
        self.register(2, color, 1, self.initial_state)
        self.register(600, color, 3, self.initial_state)
        self.register(300, color, 2, self.initial_state)

        # start the sunrise
        self.register(240, put, 2, {'data': {
                'ct': 497,
                'bri': 0,
                'transitiontime': 600 * TT_SEC
            }
        })

        self.register(90, color, [[1, 3]], {
                'r': 254,
                'g': 133,
                'b': 0,
                'data': {
                    'bri': 90,
                    'transitiontime': 480 * TT_SEC
                }
            }
        )

        self.register(510, color, 2, {
                'r': 150,
                'g': 254,
                'b': 0,
                'data': {
                    'bri':254,
                    'transitiontime': 420 * TT_SEC
                }
        })

        self.register(400, put, [[1,3]], {'data': {
                'ct': 440,
                'bri': 140,
                'transitiontime': 230 * TT_SEC
            }
        })
        self.register(0, put, 2, {'data': {
                'ct': 350, 
                'bri': 190,
                'transitiontime': 300 * TT_SEC
            }
        })

        self.register(230, put, [[1,3]], {'data': {
                'ct': 370,
                'bri': 200,
                'transitiontime': 360 * TT_SEC
            }
        })

        self.register(100, put, 2, {'data': {
                'ct': 320,
                'bri': 240,
                'transitiontime': 360 * TT_SEC
            }
        })

        self.register(360, put, [[1,2,3]], {'data': {
                'ct': 290,
                'bri': 254,
                'transitiontime': 900 * TT_SEC
            }
        })


if __name__ == '__main__':
    sunrise = SunriseScript(time_dilation=1)
    sunrise.generateCues()
    sunrise.execute()
